﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GKQC.DbHelper.DbModels;
using GKQC.DbHelper.Dao;
using SqlSugar;
using System.ComponentModel;
using GKQC.Common;

namespace GKQC.DbHelper.DbModels
{
    [SugarTable("t_sys_users")]
    public class UserModel
    {
        public UserModel()
        {
            UserCode = string.Empty;
            UserName = string.Empty;
            Password = string.Empty;
            Dept = string.Empty;
            Email = string.Empty;
            IsUse = true;
            IsAdmin = false;
        }

        [SugarColumn(IsPrimaryKey = true)] //是主键
        public string UserCode { get; set; }
        public string UserName { get; set; }
        public string Password { get; set; }
        public string Email { get; set; }
        public string Dept { get; set; }
        public bool IsUse { get; set; }
        public bool IsAdmin { get; set; }
        public string GroupCode { get; set; }

        [SugarColumn(IsIgnore = true)]
        public string OnlineId { get; set; }
        [SugarColumn(IsIgnore = true)]
        public DateTime? LoginTime { get; set; }
        [SugarColumn(IsIgnore = true)]
        public DateTime? LoginServerTime { get; set; }

        public DateTime GetServerTime()
        {
            try
            {
                TimeSpan ts1 = new TimeSpan(LoginTime.Value.Ticks);
                TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts = ts1.Subtract(ts2).Duration();
                return LoginServerTime.Value.AddSeconds(ts.TotalSeconds);
            }
            catch(Exception ex)
            {
                Logger.LogError(ex);
            }

            return DateTime.Now;
        }

        [SugarColumn(IsIgnore = true)]
        public List<UserRightModel> UserRights { get; set; }

        [SugarColumn(IsIgnore = true)]
        public List<UserRightModel> UserGroupRights { get; set; }
    }
}
